package com.leyou.item.client;

import com.leyou.common.vo.PageResult;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient(value = "item-service")
public interface ItemClient {

    /**
     * 分页查询商品
     * @param page
     * @param rows
     * @param saleable
     * @param key
     * @return
     */
    @GetMapping("/spu/page")
    PageResult<SpuDTO> querySpuByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows,
            @RequestParam(value = "saleable", defaultValue = "true") Boolean saleable,
            @RequestParam(value = "key", required = false) String key);

	/**
     * 根据spuID查询spuDetail
     * @param id spuID
     * @return SpuDetail
     */
    @GetMapping("/spu/detail")
    SpuDetailDTO querySpuDetailById(@RequestParam("id") Long id);

    /**
     * 根据spu的id查询sku
     * @param id
     * @return
     */
    @GetMapping("sku/of/spu")
    List<SkuDTO> querySkuBySpuId(@RequestParam("id") Long id);

    @GetMapping("groups/of/category")
    List<SpecGroupDTO> querySpecGroupById(@RequestParam("id") Long cid);

    @GetMapping("category/list")
    List<CategoryDTO> queryByIds(@RequestParam("ids") List<Long> idList);

    @GetMapping("brand/{id}")
    BrandDTO queryByBrandId(@PathVariable("id") Long id);

    @GetMapping("spec/params")
    List<SpecParamDTO> querySpecParams(
            @RequestParam(value = "gid", required = false) Long gid,
            @RequestParam(value = "cid", required = false) Long cid,
            @RequestParam(value = "searching", required = false) Boolean searching
    );

    @GetMapping("brand/list")
    List<BrandDTO> queryBrandByIds(@RequestParam("list") List<Long> bids);


    @GetMapping("spu/querySpuById/{id}")
    SpuDTO querySpuById(@PathVariable("id")Long id);

    @GetMapping("spec/of/category")
    List<SpecGroupDTO> querySpecsByCid(@RequestParam("id") Long id);

    @GetMapping("sku/list")
    List<SkuDTO> querySkuByIds(@RequestParam("ids")List<Long> ids);

    /**
     * 减库存
     * @param cartMap 商品id及数量的map
     */
    @PutMapping("/stock/minus")
    Void minusStock(@RequestBody Map<Long, Integer> cartMap);


    //加库存

    @PutMapping("/stock/plus")
    Void plusStock(@RequestBody Map<Long, Integer> cartMap);


}